package com.example.firstdemo.ui.screens.splash

import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.runtime.LaunchedEffect
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.example.firstdemo.ui.screens.pages.login.navigateToLogin
import kotlinx.coroutines.delay
import kotlinx.serialization.Serializable


@Serializable
object Splash

fun NavGraphBuilder.splashDestination(
    navController: NavController
) {
    composable<Splash>(
        enterTransition = { fadeIn() },
        exitTransition = { fadeOut() },
        popEnterTransition = { fadeIn() },
        popExitTransition = { fadeOut() }
    ) {
        LaunchedEffect(Unit) {
            delay(1000)
            navController.navigateToLogin {
                popUpTo(Splash) {
                    inclusive = true
                }
            }
        }
        SplashScreen()
    }
}
